﻿using System;
using System.Collections.Generic;
using FacebookWrapper.ObjectModel;

namespace Desktop_Facebook
{
	internal class CSVBirthdaySerializer : AbstractCSVSerializer
	{
		private const string k_BirthdaySubjectLine = @"{0}'s Birthday!";

		public Dictionary<string, CustomDate> BirthdaysToSave {	get; set; }

		protected override List<List<string>> GetRows()
		{
			List<List<string>> rows = new List<List<string>>();

			if (Session.Instance.LoggedInUser != null)
			{
				List<string> header = new List<string>();

				header.Add("Subject");
				header.Add("Start Date");
				header.Add("End Date");
				header.Add("All Day Event");
				header.Add("Description");

				rows.Add(header);

				foreach (User currentFriend in Session.Instance.LoggedInUser.Friends)
				{
					if (BirthdaysToSave.ContainsKey(currentFriend.Id))
					{
						List<string> row = new List<string>();

						CustomDate currentBirtday = BirthdaysToSave[currentFriend.Id];
						string dateString = string.Format(@"{0}/{1}/{2}", currentBirtday.Date.Day.ToString(), currentBirtday.Date.Month.ToString(), DateTime.Today.Year.ToString());

						row.Add(string.Format(k_BirthdaySubjectLine, currentFriend.Name.ToString()));
						row.Add(dateString);
						row.Add(dateString);
						row.Add(Boolean.TrueString);
						row.Add(string.Format(k_BirthdaySubjectLine, currentFriend.Name.ToString()));

						rows.Add(row);
					}
				}
			}

			return rows;
		}
	}
}
